package com.hzqy.service.label;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.label.LabelDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.CmCatalogVo;
import com.hzqy.web.vo.CmLabelVo;
import com.hzqy.web.vo.PmsZTreeVo;

@Service
public class LabelServiceBean extends GenericServiceBean<CmLabelVo, LabelDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private LabelDao labelDao;

	@Override
	public LabelDao getEntityDao() {
		return labelDao;
	}
	
	public List<PmsZTreeVo> selectLabelList(CmLabelVo labelVo) {
		List<PmsZTreeVo> ptvList = new ArrayList<PmsZTreeVo>();
		List<CmLabelVo> lvList = labelDao.selectLabelList(labelVo);
		for(int i=0; i<lvList.size();i++){
			PmsZTreeVo ptv = new PmsZTreeVo();
			ptv.setId(lvList.get(i).getF_label_id()+"");
			ptv.setName(lvList.get(i).getF_label_name());
			ptv.setpId(lvList.get(i).getF_label_parentid()+"");
			ptv.setUrl("");
			ptvList.add(ptv);
		}
		return ptvList;
	}
	
	public int deleteLabel(int f_label_id) {
		labelDao.deleteLabel(f_label_id);
		return 1;
	}
	
	public int insertLabel(CmLabelVo labelVo) {
		int flag = 0;
		if(labelVo==null || labelVo.getF_label_name()==null) {
			flag = -1;
		}
		if(flag ==0) {
			labelDao.insertLabel(labelVo);
			return 1;
		}
		return flag;
	}
	
	public CmLabelVo selectLabel(int f_label_id) {
		return labelDao.selectLabel(f_label_id);
	}
	
	public int updateLabel(CmLabelVo labelVo) {
		int flag = 0;
		if(labelVo==null || labelVo.getF_label_name()==null) {
			flag = -1;
		}
		if(flag ==0) {
			labelDao.updateLabel(labelVo);
			return 1;
		}
		return flag;
	}
}
